<template>
  <basic-container>
    <div>
      <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :defaults.sync="showColumn"
               :permission="permissionList"
               :before-open="beforeOpen"
               @sortable-change="sortableChange"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @filter="filterChange"
               @sort-change="sortChange"
               @row-dblclick="handleRowDBLClick"               
               >
      <template slot-scope="scope" slot="newNodeForm">
        <div style="float:right;">
        </div>
      </template>
      <template slot-scope="scope" slot="newNodeLabel">
        <div style="float:right;">
        </div>
      </template>
      <template slot-scope="scope" slot="menuLeft">
        <el-button type="primary"
                   size="small"
                   icon="el-icon-plus"
                   v-if="permission.general_flow_info_add"
                   @click.stop="openAddNewNodeDialog">新 增
        </el-button>
        <el-button type="primary"
                   size="small"
                   icon="el-icon-plus"
                   v-if="permission.general_flow_info_batch_add"
                   @click.stop="openBatchAddDialog">批量新增
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="permission.general_flow_info_batch_delete"
                   @click.stop="handleDelete">删 除
        </el-button>
      </template>
      <template slot="menuRight">
        <el-button v-if="permission.general_flow_info_download" type="default" @click.stop="exportExcel"  title="下载" icon="el-icon-download" circle size="small"></el-button>
      </template>
    </avue-crud>
  </div>
  <!-- 
      新增节点对话框
  --> 
    <el-dialog title="新增节点"  width="60%" top="20vh" :modal='false'   :close-on-click-modal='false' :visible.sync="addNewNodeDialog">
      <avue-form ref="newNode" v-model="newNodeData" :option="newNodeOption" @submit="rowSave">
        <template slot-scope="scope" slot="menuForm">
          <el-button icon="el-icon-close" size="small" @click="addNewNodeDialog = false">关闭</el-button>
        </template>
      </avue-form>
    </el-dialog> 
    <!-- 
      批量添加数据对话框
     -->
    <el-dialog title="批量导入流程节点" width='80%' top="20vh" :modal='false'  :close-on-click-modal='false' :visible.sync="batchAddDialog">
      <el-tag>
        节点编号，
        节点名字，
        节点序号，
        是否子流程
      </el-tag>
      <el-input
        type="textarea"
        :autosize="{ minRows: 10, maxRows: 20}"
        placeholder="请直接从excel粘贴内容"
        v-model="importDataArea">
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click="handleImport($event)" data-clipboard-target="#pathText">开始导入</el-button>
        <el-button size="small" @click="batchAddDialog = false">取 消</el-button>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
import {querySysRoleTree} from '@/api/system/sysRoleApi';
import {queryGeneralFlowInfoListPage} from '@/api/general/flow/generalFlowInfoApi';
import {querySysToolColumnsListPage} from '@/api/tool/sysToolColumnsApi';
import {exportGeneralFlowNodeConfigExcel,saveOrUpdateGeneralFlowNodeConfig,saveOrUpdateGeneralFlowNodeConfigList,saveGeneralFlowNodeConfig,saveGeneralFlowNodeConfigList,deleteGeneralFlowNodeConfig,queryGeneralFlowNodeConfig,queryGeneralFlowNodeConfigListPage,updateGeneralFlowNodeConfig,deleteGeneralFlowNodeConfigList} from '@/api/general/flow/generalFlowNodeConfigApi';
import {mapGetters} from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import {filterFormat} from '@/util/util';
export default {
  props: {
    flowInfo: {
      type: Object,
      default: ''
    }
  },
  data() {
    return {
      //角色列表
      roleList: [],
      // 审批树列表
      treeList: [],

      // 新增节点表单定义
      addNewNodeDialog: false,
      newNodeOption: {
        menuBtn:true,
        emptyBtn:false,
        menuSpan:24,
        labelWidth: 120,
        column: [
          {
            label: '节点编号',
            prop: 'nodeNo', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            maxlength:10,
            rules: [{
              max: 10,
              message: '请输入内容长度为10',
              trigger: 'blur'
            },
            {
              required:  true,
              message: '请输入内容',
              trigger: 'blur'
            }
            ],
            dicData:[]
          },
          {
            label: '节点名称',
            prop: 'nodeName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            rules: [{
              required:  true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '节点序号',
            prop: 'orderSeq', 
            type: 'number', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            maxRows: 100,
            minRows: 1,
            rules: [{
              required:  true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '是否子流程',
            prop: 'isSubFlowFlag', 
            type: 'radio', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            value: '0',
            rules: [{
              required:  true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[
              {
                label: '否',
                value: '0'
              },
              {
                label: '是',
                value: '1'
              }
            ]
          }
        ]
      },
      newNodeData: [],
      // 表单对应的数据表名字
      tableName: '',
      importDataArea: '',
      batchAddDialog: false,
      form: {},
      selectionList: [],
      loading: true, 
      showColumn: [],
      option: {
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 120,
        dialogTop: '50',
        indexFixed:true, 
        stripe:true,
        calcHeight: 80,
        searchShow: false,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        selection: true,
        addBtn: false,
        viewBtn: true,
        delBtn: false,
        cancelBtn: true,
        printBtn:false,
        saveBtn: true,
        editBtnText: '编辑节点',
        filterBtn:false,          
        menuWidth: 200,
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '90%',
        highlightCurrentRow:  true,
        column:[
          {
            label: '节点编号',
            prop: 'nodeNo', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            display:false,
            dicData:[]
          },
          {
            label: '节点名称',
            prop: 'nodeName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            display:false, 
            dicData:[]
          },
          {
            label: '是否子流程',
            prop: 'isSubFlowFlag', 
            type: 'radio', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            display:false,
            value: '0',
            rules: [{
              required:  true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[
              {
                label: '否',
                value: '0'
              },
              {
                label: '是',
                value: '1'
              }
            ]
          },
          {
            label: '通知方式',
            prop: 'noticeWay', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            overHidden: true,
            display:false,
            rules: [{
              required:  false,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[]
          },
          
          {
            label: '是否可转派',
            prop: 'isTransferFlag', 
            type: 'radio', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            display:false,
            rules: [{
              required:  false,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[
              {
                label: '否',
                value: '0'
              },
              {
                label: '是',
                value: '1'
              }
            ],
          },
          {
            label: '是否可委托',
            prop: 'isDelegateFlag', 
            type: 'radio', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            display:false,
            rules: [{
              required:  false,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData:[
              {
                label: '否',
                value: '0'
              },
              {
                label: '是',
                value: '1'
              }
            ],
          },
        ],
        tabs: false,
        menuBtn: true,
        group: [
          {
            label: '基本信息',
            prop: 'basicInfo',
            icon:'el-icon-info',
            display: true,
            column: [
              {
                label: '节点编号',
                prop: 'nodeNo', 
                type: 'input', 
                search: true,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 12,
                sortable: false,
                hide: false,
                overHidden: true,
                maxlength:10,
                rules: [{
                  max: 10,
                  message: '请输入内容长度为10',
                  trigger: 'blur'
                },
                {
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }
                ],
                dicData:[]
              },
              {
                label: '节点名称',
                prop: 'nodeName', 
                type: 'input', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 12,
                sortable: false,
                hide: false,
                overHidden: true,
                rules: [{
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[]
              },
              
              {
                label: '节点序号',
                prop: 'orderSeq', 
                type: 'number', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                maxRows: 100,
                minRows: 1,
                rules: [{
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[]
              },
              {
                label: '是否可追回',
                prop: 'isRollbackFlag', 
                type: 'radio', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                value: '0',
                rules: [{
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '否',
                    value: '0'
                  },
                  {
                    label: '是',
                    value: '1'
                  }
                ],
              },
              {
                label: '是否子流程',
                prop: 'isSubFlowFlag', 
                type: 'radio', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                value: '0',
                rules: [{
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '否',
                    value: '0'
                  },
                  {
                    label: '是',
                    value: '1'
                  }
                ],
                change: ({value,column}) => {
                  if(value == '0'){
                    this.findObject(this.option.group[0].column, 'subFlowId').disabled = true;  
                  }
                  else{
                    this.findObject(this.option.group[0].column, 'subFlowId').disabled = false;
                  }
                }
              },
              {
                label: '选择子流程',
                prop: 'subFlowId', 
                type: 'select', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                disabled: true,
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                props: {
                  label: 'flowName',
                  value: 'id',
                },
                dicData:[]
              },
              
              {
                label: '是否可转派',
                prop: 'isTransferFlag', 
                type: 'radio', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                value: '1',
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '否',
                    value: '0'
                  },
                  {
                    label: '是',
                    value: '1'
                  }
                ],
              },
              {
                label: '是否可委托',
                prop: 'isDelegateFlag', 
                type: 'radio', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                value: '1',
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '否',
                    value: '0'
                  },
                  {
                    label: '是',
                    value: '1'
                  }
                ],
              },
             
              {
                label: '协同方式',
                prop: 'gotoType', 
                type: 'radio', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                value: '',
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '无',
                    value: ''
                  },
                  {
                    label: '或签',
                    value: '0'
                  },
                  {
                    label: '会签',
                    value: '1'
                  }
                ],
                change: ({value,column}) => {
                  if(value == '1'){
                    this.findObject(this.option.group[0].column, 'passRate').disabled = false;  
                  }
                  else{
                    this.findObject(this.option.group[0].column, 'passRate').disabled = true;
                  }
                }
              },
              {
                label: '通过比例(%)',
                prop: 'passRate', 
                type: 'number', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 6,
                sortable: false,
                hide: false,
                overHidden: true,
                precision:2,
                row:true, 
                value: 100,
                disabled: true,
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[],
              },
              
              {
                label: '受控方式',
                prop: 'controlWay', 
                type: 'radio', 
                search: false,
                span: 12,
                hide: false,
                overHidden: true,
                value: '0',
                rules: [{
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '前置节点通过一个可达',
                    value: '0'
                  },
                  {
                    label: '前置节点全部通过后可达',
                    value: '1'
                  }
                ]
              },
              {
                label: '审批模式',
                prop: 'easyModeFlag', 
                type: 'radio', 
                search: false,
                span: 12,
                hide: false,
                overHidden: true,
                value: '1',
                rules: [{
                  required:  true,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '简单',
                    value: '1'
                  },
                  {
                    label: '完整',
                    value: '2'
                  }
                ]
              },
              {
                label: '处理JAVA类名',
                prop: 'javaClassName', 
                type: 'input',
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 24,
                sortable: false,
                hide: true,
                overHidden: true,
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[]
              },
            ]
          },
          {
            label: '执行状态配置',
            prop: 'basicInfo', 
            icon:'el-icon-setting',
            addDisplay:false,
            column: [
              {
                label: '状态控制列表',
                prop: 'execStatusList',   
                type: 'dynamic', 
                span:24,
                children: {
                  align: 'center',
                  headerAlign: 'center', 
                  column: [
                    { 
                      label: '节点状态(必输)',
                      prop: 'nodeStatus',
                      type: 'select',
                      width: 150,
                      rules:[{
                        required:  true,
                        message: '请输入内容',
                      }],
                      dicData: []
                    }, 
                    { 
                      label: '跳转条件(非必填)',
                      prop: 'gotoCondition',
                      type: 'input',
                      width: 300,
                      rules:[{
                        required:  false,
                        message: '请输入内容',
                      }]
                    }, 
                    {
                      label: '下个节点(非必输)',
                      prop: 'nextProccessId',
                      type: 'select',
                      multiple: true,
                      filterable: true,
                      props: {
                        label: 'nodeName',
                        value: 'id',
                      },
                      rules:[{
                        required:  false,
                        message: '请输入内容',
                      }],
                      dicData: []
                    }, 
                    { 
                      label: '流转方式',
                      prop: 'flowTransferMode',
                      type: 'select',
                      width: 120,
                      value: '0',
                      rules:[{
                        required:  true,
                        message: '请输入内容',
                      }],
                      dicData: [
                        {
                          label: '人员可选',
                          value: '1'
                        },
                        {
                          label: '所有人',
                          value: '0'
                        }
                      ]
                    }, 

                    {
                      label: '节点阶段状态',
                      prop: 'nodeStageStatus',
                      type: 'select',
                      width: 120,
                      rules:[{
                        required:  true,
                        message: '请输入内容',
                      }],
                      dicData: []
                    },
                    {
                      label: '参与会签',
                      prop: 'joinPassFlag',
                      type: 'switch',
                      width: 80,
                      value: '1',
                      rules:[{
                        required:  false,
                        message: '请输入内容',
                      }],
                      dicData: [
                        {
                          label:'',
                          value:'0'
                        },
                        {
                          label:'',
                          value:'1'
                        }
                      ]
                    }
                  ]
                }
              }
            ]
          },
          {
            label: '执行经办配置',
            prop: 'optUser', 
            icon:'el-icon-user',
            addDisplay:false,
            column: [
              {
                label: '通知处理类',
                prop: 'noticeWay', 
                type: 'checkbox', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 12,
                sortable: false,
                hide: true,
                overHidden: true,
                display: false,
                rules: [{
                  required:  false,
                  message: '请选择内容',
                  trigger: 'blur'
                }]
              },
              {
                label: '通知处理类',
                prop: 'noticeProcessClassName', 
                type: 'input', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 12,
                sortable: false,
                hide: true,
                overHidden: true,
                rules: [{
                  required:  false,
                  message: '请选择内容',
                  trigger: 'blur'
                }]
              },
              {
                label: '超时是否通知',
                prop: 'isOvertimeNoticeFlag', 
                type: 'switch', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 12,
                sortable: false,
                hide: true,
                overHidden: true,
                value: '1',
                rules: [{
                  required:  false,
                  message: '请选择内容',
                  trigger: 'blur'
                }],
                dicData: [
                  {
                    label:'否',
                    value: '0'
                  },
                  {
                    label:'是',
                    value: '1'
                  }
                ]
              },
              {
                label: '经办人列表',
                prop: 'optUserList', 
                type: 'dynamic', 
                span: 24,
                children: {
                  align: 'center',
                  headerAlign: 'center', 
                  column: [
                    {
                      label: '经办类型',
                      prop: 'operatorType',
                      type: 'select',
                      width: 120,
                      value: 'user',
                      rules:[{
                        required:  true,
                        message: '请输入内容',
                      }],
                      dicData: [{
                        label: '人员',
                        value: 'user'
                      }, 
                      {
                        label: '角色',
                        value: 'role'
                      }, 
                      {
                        label: '审批树',
                        value: 'tree'
                      }],
                      change: ({value,column}) => {
                        //console.log('234567890000');
                        setTimeout(() => {
                          if(value == 'tree'){
                            this.findObject(this.option.group[2].column[1].children.column, 'optValues').remote = false;
                            this.findObject(this.option.group[2].column[1].children.column, 'optValues').dicData = this.treeList;                        
                          }
                          else if(value == 'role'){
                            this.findObject(this.option.group[2].column[1].children.column, 'optValues').remote = false;
                            this.findObject(this.option.group[2].column[1].children.column, 'optValues').dicData = this.roleList; 
                          }
                          else if(value == 'user'){
                            this.findObject(this.option.group[2].column[1].children.column, 'optValues').remote = true;
                            this.findObject(this.option.group[2].column[1].children.column, 'optValues').dicData = []; 
                          }
                        }, 500);
                      }
                    },
                    {
                      label: '列表',
                      prop: 'optValues',
                      type: 'select',
                      multiple: true,
                      filterable: true,
                      remote: true,
                      props: {
                        label: 'userName',
                        value: 'realName',
                      },
                      dicFlag: false,
                      dicMethod:'get',
                      dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&remote=yes&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
                      rules: [{
                        type: 'array',
                        required: false,
                        message: '请输入内容',
                      }],
                      dicData:[],
                    }, 
                  ]
                }
              },
              {
                label: '抄送人列表',
                prop: 'ccUserList', 
                type: 'select',
                multiple: true,
                filterable: true,
                remote: true,
                span:24,
                props: {
                  label: 'userName',
                  value: 'realName',
                },
                dicFlag: false,
                dicMethod:'get',
                dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&remote=yes&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
                rules: [{
                  type: 'array',
                  required: false,
                  message: '请输入内容',
                }],
                dicData:[],
              },
              {
                label: '抄送角色',
                prop: 'ccRoleName',
                type: 'select',
                multiple: true,
                filterable: true,
                maxlength: 50,
                span:24,
                props: {
                  label: 'userName',
                  value: 'realName',
                },
                rules: [{
                  type: 'array',
                  required: false,
                  message: '请输入内容',
                }],
                dicData:[],
              }, 
            ]
          },
          {
            label: '流程表单控制',
            prop: 'basicInfo',
            icon: 'el-icon-s-grid',
            addDisplay:false,
            column: [
              { 
                label: '表单ID',
                prop: 'formId', 
                type: 'input', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 24,
                sortable: false,
                hide: true,
                overHidden: true,
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[]
              },
              { 
                label: '表单分组隐藏',
                prop: 'hideFormGroupList', 
                type: 'input', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: true,
                span: 24,
                sortable: false,
                hide: true,
                overHidden: true,
                value: '[]',
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }]
              },
              {
                label: '表单权限列表',
                prop: 'formPrivilegeList', 
                type: 'dynamic', 
                span: 24,
                children: {
                  align: 'center',
                  headerAlign: 'center', 
                  column: [
                    {
                      label: '权限',
                      prop: 'privilege',
                      type: 'select',
                      width:120,
                      value: '0',
                      rules:[{
                        required:  true,
                        message: '请输入内容',
                      }],
                      dicData: [{
                        label: '不可见',
                        value: '0'
                      }, 
                      {
                        label: '只读',
                        value: '1'
                      },
                      {
                        label: '必输',
                        value: '2'
                      }]
                    },
                    {
                      label: '字段名',
                      prop: 'fieldName',
                      type: 'select', 
                      multiple: true,
                      filterable: true,
                      rules:[{
                        type: 'array',
                        required:  true,
                        message: '请输入内容',
                      }],
                      dicData: []
                    }, 
                  ]
                }
              },
            ]
          },
          {
            label: '处理超时设置',
            prop: 'basicInfo', 
            icon: 'el-icon-time',
            column: [
              {
                label: '节点等待时长',
                prop: 'nodeWaitDuration', 
                type: 'number', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 7,
                sortable: false,
                hide: true,
                overHidden: true,
                minRows: '1',
                maxRows: '999999',
                precision: 0,
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[]
              },
              {
                label: '单位',
                prop: 'timeUnit', 
                type: 'select', 
                search: false,
                searchMmultiple: false,
                searchLabelWidth: 100,
                multiple: false,
                span: 5,
                sortable: false,
                hide: true,
                overHidden: true,
                value: 'd',
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[
                  {
                    label: '分钟',
                    value: 'm'
                  },
                  {
                    label: '小时',
                    value: 'h'
                  },
                  {
                    label: '天',
                    value: 'd'
                  }
                ]
              },
              {
                label: '超时通知方式',
                prop: 'overtimeNoticeWay', 
                type: 'checkbox', 
                multiple: false,
                span: 12,
                sortable: false,
                hide: true,
                overHidden: true,
                rules: [{
                  required:  false,
                  message: '请输入内容',
                  type: 'array',
                  trigger: 'blur'
                }],
                dicData:[]
              },
              {
                label: '超时通知列表',
                prop: 'overtimeNoticeList', 
                type: 'select',
                multiple: true,
                filterable: true,
                remote: true,
                span:24,
                props: {
                  label: 'userName',
                  value: 'realName',
                },
                dicFlag: false,
                dicMethod:'get',
                dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&remote=yes&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
                rules: [{
                  type: 'array',
                  required: false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[],
              }, 
              {
                label: '超时通知角色',
                prop: 'overtimeNoticeRoleName',
                type: 'select',
                multiple: true,
                filterable: true,
                maxlength: 50,
                span:24,
                props: {
                  label: 'userName',
                  value: 'realName',
                },
                rules: [{
                  type: 'array',
                  required: false,
                  message: '请输入内容',
                  trigger: 'blur'
                }],
                dicData:[],
              }, 
            ]
          }
        ]
      },
      data: [],
      // 请求参数区
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition:[],
        orderRule: {},
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {}
    };
  },
  computed: {
    ...mapGetters(['website','userInfo','orgTree','permission']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.general_flow_info_add, false),
        viewBtn: this.vaildData(this.permission.general_flow_info_view, false),
        delBtn: this.vaildData(this.permission.general_flow_info_delete, false),
        editBtn: this.vaildData(this.permission.general_flow_info_edit, false),
        printBtn: this.vaildData(this.permission.general_flow_info_print, false),
        searchBtn:this.vaildData(this.permission.general_flow_info_search, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push({id : ele.id});
      });
      return ids;
    } 
  },
  methods: { 
    /** 
     * 新增节点
    */
    openAddNewNodeDialog(){
      this.addNewNodeDialog = true;
    },
    /**
     * 加载列表数据
     */
    onLoad() {
      this.loading = true;
      this.reqParams =  {
        singleBody: {
          flowId: this.flowInfo.id
        },
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: {
          order: 'ascending',
          prop: 'orderSeq'
        },
        currentPage: 1, 
        pageSize: 9999,
      }
      this.commonData = reqCommonMsg(this.reqParams)
      queryGeneralFlowNodeConfigListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.page.total = data.total;
        this.data = data.listBody;
        let nodeList = []
        this.data.forEach(element => {
          element.execStatusList = [];
          element.optUserList = [];
          element.formPrivilegeList = [];
          element.overtimeNoticeList = [];
          nodeList.push(
            {
              id: element.id,
              nodeName: element.nodeName
            }
          )
        });
        this.handleNodeList(nodeList);
        this.loading = false;
        this.selectionClear();
      }, error => {
        this.loading = false; 
      });
    },
    /**
     * 处理节点列表控件
     */
    handleNodeList(data){
      this.findObject(this.option.group[1].column[0].children.column, 'nextProccessId').dicData = data;
    },
    /**
     * 新增一条记录
     */
    rowSave(row, done, loading) {
      this.reqParams.singleBody = row;
      this.reqParams.singleBody.flowId = this.flowInfo.id;
      this.reqParams.singleBody.execStatusList = [];
      this.reqParams.singleBody.noticeWay =  [];
      this.reqParams.singleBody.optUserList =  [];
      this.reqParams.singleBody.hideFormGroupList =  [];
      this.reqParams.singleBody.formPrivilegeList =  [];
      this.reqParams.singleBody.overtimeNoticeList =  [];
      this.reqParams.singleBody.overtimeNoticeWay =  [];
      this.reqParams.singleBody.ccUserList =  [];
      this.reqParams.singleBody.ccRoleName =  [];
      this.reqParams.singleBody.overtimeNoticeRoleName =  [];
      this.commonData = reqCommonMsg(this.reqParams)
      saveGeneralFlowNodeConfig(this.commonData).then(() => {
        done();
        this.singleBody={};
        this.onLoad();
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '操作成功!'
        });
        this.addNewNodeDialog = false;
      }, error => {
        //this.$console.log(error);
      });         
      //this.$console.log("row = ",row ,loading)
    },

    /**
     * 修改一条记录
     */
    rowUpdate(row, index, done, loading) { 
      //this.$console.log('=====row =====',row);
      this.reqParams.singleBody = row;
      this.commonData = reqCommonMsg(this.reqParams)
      updateGeneralFlowNodeConfig(this.commonData).then(() => {
        done();
        this.singleBody={}
        this.onLoad();
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        loading();
      });
      //this.$console.log('loading = ',loading)
    },
    /**
     * 删除一条记录
     */
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteGeneralFlowNodeConfig(this.commonData);
        })
        .then(() => {
          this.onLoad();
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => {});
    },
    /**
     * 双击打开详细窗口
     */
    handleRowDBLClick (row, event) {
      if(this.permission.general_flow_info_dbclick){
        this.$refs.crud.rowView(row,row.$index);
      }
    },
   
    /**
     * 搜索重置
     */
    searchReset() {
      this.conditions =[];
      this.singleBody = {};
      this.onLoad();
    },
    /**
     * 搜索
     */
    searchChange(params, done) {
      this.singleBody = params
      this.page.currentPage = 1;
      this.onLoad();
      done();
    },
    refreshChange(){
      this.onLoad();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * 处理批量删除
     */
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.listBody = this.ids;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteGeneralFlowNodeConfigList(this.commonData);
        })
        .then(() => {
          this.onLoad();
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        }).catch(() => {});
    },
    /**
     * 拷贝记录
     */
    handleCopy(row){
      this.$confirm('确定复制数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading=true;
        let copyValue=row;
        copyValue.id='0';
        copyValue.dataSign='0'
        copyValue.tableName='拷贝 '+ copyValue.tableName; 
        this.reqParams.singleBody = copyValue;
        this.commonData = reqCommonMsg(this.reqParams)
        saveSysToolTables(this.commonData).then(() => {
          this.singleBody={};
          this.onLoad();
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          });
          this.loading=false;
        }, error => {
          //this.$console.log(error);
          this.loading=false;
        });
      }).catch(() => {});       
    },
    /**
     * 批量新增记录
     */
    openBatchAddDialog(){
      this.batchAddDialog = true;
    },
    /**
     * 批量新增 
     */ 
    handleImport() {
      this.loading=true;
      var dataList = new Array();
      if(this.importDataArea){
        var lineList = this.importDataArea.split('\n')
        lineList.forEach((element,index) => {
          if(element.trim() != ''){
            var field = element.split('\t')
            var fieldList = {
              flowId:this.flowInfo.id,
              nodeNo:field[0].trim(),
              nodeName:field[1].trim(),
              orderSeq:field[2].trim(), 
              isSubFlowFlag:field[3].trim(),
              execStatusList: [],
              noticeWay: [],
              optUserList: [],
              hideFormGroupList: [],
              formPrivilegeList: [],
              overtimeNoticeList: [],
              overtimeNoticeWay: []
            }
            dataList[index] = fieldList
            //this.$console.log('fieldList = ',fieldList)
          }
        });
        //批量写入记录
        this.reqParams.listBody = dataList;
        this.commonData = reqCommonMsg(this.reqParams)
        saveGeneralFlowNodeConfigList(this.commonData).then(() => {
          this.loading=false;
          this.onLoad(this.page);
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          });
          this.batchAddDialog = false;
        }, error => {
          //this.$console.log(error);
          this.loading=false;
          loading();
        });      
        //this.$console.log('lineList=',dataList)
      }
      else{
        this.loading=false;
        this.$message({
          customClass:'zZindex',
          type: 'warning',
          message: '数据格式不正确!'
        });
      }
    },
    /**
     * 打开编辑、查询弹窗前查询记录
     */  
    beforeOpen(done, type) {
      this.reqParams =  {
        singleBody: {
          id:this.form.id
        }
      }
      let commonData = reqCommonMsg(this.reqParams)
      if (['edit', 'view'].includes(type)) {
        queryGeneralFlowNodeConfig(commonData).then(res => {
          this.form = res.data.body.singleBody;
          this.form.execStatusList = JSON.parse(this.form.execStatusList);
          this.form.optUserList = JSON.parse(this.form.optUserList);
          this.form.formPrivilegeList = JSON.parse(this.form.formPrivilegeList);
          // this.form.hideFormGroupList = JSON.parse(this.form.hideFormGroupList);
          this.form.noticeWay = JSON.parse(this.form.noticeWay);
          this.form.overtimeNoticeWay = JSON.parse(this.form.overtimeNoticeWay);
          this.form.overtimeNoticeList = JSON.parse(this.form.overtimeNoticeList);
          this.form.ccUserList = JSON.parse(this.form.ccUserList);
          this.form.ccRoleName = JSON.parse(this.form.ccRoleName);
          this.form.overtimeNoticeRoleName = JSON.parse(this.form.overtimeNoticeRoleName);
          done();
        });
      }
      if (['add'].includes(type)) {
        done();
      }
      //if(this.findObject(this.option.group[0].column, 'subFlowId').dicData.length == 0){
      this.getAllFlowByFlowType();
      //}
    },
    /**
     * 获取该流程类型的所有流程，用于展示子流程
     */
    getAllFlowByFlowType() { 
      this.reqParams =  {
        singleBody: {
          bizType: this.flowInfo.bizType
        },
        currentPage: 1, 
        pageSize: this.website.maxPageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      queryGeneralFlowInfoListPage(this.commonData).then(res => {
        let data = [];
        res.data.body.listBody.forEach(element => {
          if(element.id != this.flowInfo.id){
            data.push({
              id: element.id,
              flowName: element.flowName
            });
          }
        });
        this.findObject(this.option.group[0].column, 'subFlowId').dicData = data;
      }, error => {
      });
    },
    /**
     * 翻页查询
     */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    /**
     * 更改每页条数
     */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    /**
     * 自定义查询条件
     */
    filterChange(result) {
      this.page.currentPage = 1;
      this.conditions = filterFormat(result)
      this.onLoad();
    },
    /**
     * 列表排序
     */
    sortChange(val){
      this.orderRules=val
      this.onLoad();
    },
  
    /**
     * 导出Excel
     */
    exportExcel() {
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage:1, 
        pageSize: 100
      }
      //this.$console.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      exportGeneralFlowNodeConfigExcel(this.commonData);
    },
    /**
     * 获取业务字典参数
     */
    async getBizDict() {
      let dicData = await this.$params.getBizDict('["'+this.flowInfo.nodeStatusNo+'","'+this.flowInfo.nodeStageStatusNo+'","noticeWay"]');
      this.findObject(this.option.group[1].column[0].children.column, 'nodeStatus').dicData = dicData.nodeStatus;
      this.findObject(this.option.group[1].column[0].children.column, 'nodeStageStatus').dicData = dicData.nodeStageStatus;
      this.findObject(this.option.group[2].column, 'noticeWay').dicData = dicData.noticeWay;
      this.findObject(this.option.column, 'noticeWay').dicData = dicData.noticeWay;
      this.findObject(this.option.group[4].column, 'overtimeNoticeWay').dicData = dicData.noticeWay;
    },
    /**
     * 获取角色列表，只获取 roleType = (通过配置获取) 的 
     */
    async getRoleTreeList(){
      // 加载树形目录列表
      this.reqParams =  {
        singleBody: {
          roleType: this.flowInfo.roleType || '99'
        },
        currentPage: 1, 
        pageSize: this.website.maxPageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      await querySysRoleTree(this.commonData).then(res => {
        let treeData= res.data.body.listBody;
        let formatData = [];
        treeData.forEach(element => {
          element.children.forEach(celement => {
            formatData.push({
              realName: celement.roleName+'('+celement.roleNo+')',
              userName: '角色---'+celement.roleName+'('+celement.roleNo+')',
            })
          });
        });
        this.roleList = formatData;
        this.findObject(this.option.group[2].column[1].children.column, 'optValues').dicData = formatData;
        this.findObject(this.option.group[2].column, 'ccRoleName').dicData = formatData;
        this.findObject(this.option.group[4].column, 'overtimeNoticeRoleName').dicData = formatData;
      }, error => {
      });
    },
    /**
     * 初始化弹窗数据
     */
    initialConfigData(){
      this.onLoad();
      //获取业务字典
      setTimeout(() => {
        this.getBizDict();
      }, 1000);
      //获取角色列表
      if(this.flowInfo.roleType){
        setTimeout(() => {
          this.getRoleTreeList();
        }, 1000);
      }
    },
    /**
     * 获取对应表的字段列表
     */
    loadCloumns(tableList) {  
      let conditionList = [];
      let orCondition = [];
      if(tableList.indexOf(';') > 0){
        conditionList = tableList.split(';');
        conditionList.forEach(element => {
          orCondition.push({
            column: 'tableName',
            type: '=',
            value: element
          });
        });
      }
      this.reqParams =  {
        listBody: [{}],
        sqlCondition: [],
        sqlOrCondition: orCondition,
        orderRule: {
          prop: 'ordinalPosition',
          order: 'ascending'  //descending  fieldName
        },
        currentPage: 1, 
        pageSize: this.website.maxPageSize,
        total: 0
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysToolColumnsListPage(this.commonData).then(res => {
        const data = res.data.body.listBody;
        let dicData = [];
        data.forEach(element => {
          dicData.push({
            label: element.columnComment,
            value: element.columnName
          })
        });
        this.findObject(this.option.group[3].column[2].children.column, 'fieldName').dicData = dicData;
      }, error => {
      });
    },
  },
  created() {
    this.treeList = [
      {
        userName: '审批树',
        realName: 'tree'
      }
    ]
  }, 
  mounted() {
    this.showColumn = this.$getStore({name:  this.userInfo.userId +'generalFlowNodeConfigColumn'});
    setTimeout(() => {
      this.loadCloumns(this.flowInfo.tableList);
    }, 1000);
  },
  watch: {
    showColumn: {
      handler(newValue, oldValue) {
        this.$setStore({name:  this.userInfo.userId+'generalFlowNodeConfigColumn', content: this.showColumn});
      },
      deep: true
      //this.$setStore({name: this.userInfo.userId +'generalFlowNodeConfigColumn', content: this.showColumn});
    }, 
    flowInfo: function (val) {
    },
  }
};
</script>
<style>
</style>
